"use strict";
define(["commonUI","getTime","global"], function (
    commonUI, getTime,global
) {
    /**
     * 
     * @returns 登录函数
     */
     function login() {
        var userName=$("#userName").val().trim();
            var password=$("#password").val().trim();
            if(userName == null || userName=="" || password == null || password == ""){
                alert("登录名和登录密码不能为空");
                return;
            }
            var data = {
                userName:userName,
                password:password
            }
            global.post("web/login",function(response){
                if(response.success){
                    //登录成功 存储值
                    var data = response.data;
                    localStorage.setItem("token",data.token);
                    localStorage.setItem("loginUser",JSON.stringify(data.loginUser))
                    //跳转到主页
                    window.history.replaceState(null, "", '/bigScreen.html');
                    location.reload()
                    
                }else{
                    $("#userName").val("")
                    $("#password").val("")
                    alert(response.message)
                }
            },JSON.stringify(data))
    }
    var app = {
        init: function () {
            this.eventBind();
            getTime.getNowDate();
            getTime.getTimeInfo();
        },
        resize:function () {
            var ratioX = $(window).width() / 1920;
            var ratioY = $(window).height() / 1080;
            if (ratioX < ratioY) {
                $(".page-container").css({
                    transformOrigin: "left top",
                    transform: "scale(" + ratioX + "," + ratioX + ")"
                });
            } else {
                $(".page-container").css({
                    transformOrigin: "center top",
                    transform: "scale(" + ratioY + "," + ratioY + ")"
                });
            }
        },
        /** 事件绑定 */
        eventBind: function () {
            $(document).on("click", ".login-btn", function () {
                login()
                //window.open("bigScreen.html","_self");
            })
            window.onresize = function () {
                app.resize();
            };
        },
        
    };
    return app;
});